<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="./../templates/StakeholderPortalTemplate.xhtml">
    <ui:define name="content"> 
        <h:form id="formMain">
            <p:panel id="list">
                <p:dataTable var="type" value="#{metricManagerBean.listOfType}" emptyMessage="No record found"
                             rowIndexVar="index" rowSelectListener="#{metricManagerBean.changeMetricType}"
                             selectionMode="single" update ="metric" >
                    <p:column headerText="Type">
                        <h:outputText value="#{type.name}" />
                    </p:column>      
                </p:dataTable>
            </p:panel>
        </h:form>

        <h:form id="metric" style="width:700px; float:left">
            <p:dashboard model="#{metricManagerBean.selectedDashboard}" id="board">
                <c:forEach items="#{metricManagerBean.selectedDashboard.columns}" var="column">
                    <c:forEach items="#{column.widgets}" var="item" begin="0" >
                        <p:panel id="#{item}" header="#{metricManagerBean.getMetricMap(item).name}" style="text-align:center" 
                                 closable="#{metricManagerBean.select == 0}" closeListener="#{metricManagerBean.removeMetricFromList}" 
                                 onCloseUpdate="list grid">
                            <c:forEach begin="0" end="#{metricManagerBean.getMetricMap(item).selectListSize-1}">
                                <p>
                                    <h:outputText value="#{metricManagerBean.getMetricMap(item).selectListName}" style="font-weight: bold"/>   
                                    <h:selectOneMenu value="#{metricManagerBean.getMetricMap(item).selectVar}" >  
                                        <f:selectItems value="#{metricManagerBean.getMetricMap(item).selectList}" />                                    
                                    </h:selectOneMenu> 
                                </p>
                            </c:forEach>
                            <c:forEach begin="0" end="#{metricManagerBean.getMetricMap(item).varSize-1}">
                                <p>
                                    <h:outputText value="#{metricManagerBean.getMetricMap(item).varName}" style="font-weight: bold"/> 
                                    <p:inputText value="#{metricManagerBean.getMetricMap(item).var}" required="true"/>
                                </p>
                            </c:forEach>
                            <c:forEach begin="0" end="#{metricManagerBean.getMetricMap(item).dateListSize-1}">
                                <p>
                                    <h:outputText value="#{metricManagerBean.getMetricMap(item).dateListName}" style="font-weight: bold"/>    
                                    <p:calendar value="#{metricManagerBean.getMetricMap(item).dateList}"/>
                                </p>
                            </c:forEach>
                            <c:forEach begin="0" end="#{metricManagerBean.getMetricMap(item).outputValueSize-1}">
                                <p>
                                    <h:outputText value="#{metricManagerBean.getMetricMap(item).outputValueName}" style="font-weight: bold"/> 
                                    <h:outputText value="#{metricManagerBean.getMetricMap(item).outputValue}"/>
                                </p>
                            </c:forEach>
                            <c:forEach begin="0" end="#{metricManagerBean.getMetricMap(item).dataTableSize-1}" varStatus="tableIndex">
                                <p>
                                    <h:outputText value="#{metricManagerBean.getMetricMap(item).getDataTableName(tableIndex.index)}" style="font-weight: bold"/>   
                                    <p:dataTable var="user" value="#{metricManagerBean.getMetricMap(item).getDataTable(tableIndex.index)}" emptyMessage="No record found" paginator="true" rows="5"
                                                 first="0" rowIndexVar="rowIndex" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" >

                                        <c:forEach varStatus="item1" begin="0" end="#{metricManagerBean.getMetricMap(item).getDataTable(tableIndex.index).get(0).size-1}" > 
                                            <p:column headerText="#{metricManagerBean.getMetricMap(item).getDataTable(tableIndex.index).get(0).getValue(item1.index)}">
                                                <h:outputText value="#{metricManagerBean.getMetricMap(item).getDataTable(tableIndex.index).get(rowIndex).getValue(item1.index)}" rendered="#{rowIndex != 0}"/>
                                            </p:column>      
                                        </c:forEach> 
                                    </p:dataTable>
                                </p>
                            </c:forEach>
                            <br/>
                            <c:if test="#{metricManagerBean.getMetricMap(item).chartType == 1}">
                                <p:pieChart model="#{metricManagerBean.getMetricMap(item).model}" width="300px" rendered="#{metricManagerBean.getMetricMap(item).model != null}"/> 
                            </c:if>
                            <c:if test="#{metricManagerBean.getMetricMap(item).chartType == 2}">
                                <p:barChart model="#{metricManagerBean.getMetricMap(item).model}" width="300px" rendered="#{metricManagerBean.getMetricMap(item).model != null}"/> 
                            </c:if>
                            <c:if test="#{metricManagerBean.getMetricMap(item).chartType == 3}">
                                <p:lineChart model="#{metricManagerBean.getMetricMap(item).model}" width="300px" rendered="#{metricManagerBean.getMetricMap(item).model != null}"/> 
                            </c:if>
                            <c:if test="#{metricManagerBean.getMetricMap(item).chartType == 4}">
                                <p:columnChart model="#{metricManagerBean.getMetricMap(item).model}" width="300px" rendered="#{metricManagerBean.getMetricMap(item).model != null}"/> 
                            </c:if>
                            <p:commandButton actionListener="#{metricManagerBean.compute(item)}" type="submit" update="metric" value="Compute" rendered="#{metricManagerBean.getMetricMap(item).isCompute()}"/>
                            <p:commandButton actionListener="#{metricManagerBean.addMetricToList(item)}" type="submit" update="metric" value="Add to customized list" rendered="#{metricManagerBean.select!=0}"/>
                        </p:panel>
                    </c:forEach> 
                </c:forEach>
            </p:dashboard>   
        </h:form>
    </ui:define>
</ui:composition>